package cn.tedu.health.controller;

import cn.tedu.health.pojo.entity.HealthData;
import cn.tedu.health.response.JsonResult;
import cn.tedu.health.service.IHealthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api")
public class HealthDataController {

    @Autowired
    private IHealthDataService healthDataService;

    @PostMapping("/healthdata")
    public JsonResult recordHealthData(@RequestBody HealthData healthData) {
        healthDataService.recordHealthData(healthData);
        return JsonResult.ok();
    }

    @GetMapping("/healthdata")
    public JsonResult getHealthData(Long userId,LocalDate date) {
        HealthData healthData = healthDataService.getHealthData(userId, date);
        return JsonResult.ok(healthData);
    }

    @GetMapping("/healthdata/{userId}")
    public JsonResult getHealthDataByUserId(@PathVariable Long userId) {
        List<HealthData> healthDataList = healthDataService.getHealthDataByUserId(userId);
        return JsonResult.ok(healthDataList);
    }
}
